# /usr/bin/python3

# Author: 爱编程的章老师
# @Time: 2021/1/4 0004
# E-mail: Bluesand2010@163.com


import pygame
import sys
import time

def homework():
    pygame.init()
    screen = pygame.display.set_mode((800, 600))
    screen.fill((255,255,255))
    # 画房子主体
    rect = pygame.Rect(260,390,280,210)
    c = 102, 204, 255
    pygame.draw.rect(screen, c, rect, 0)

    # 画窗户:边框 加两条张
    rect = pygame.Rect(285,420,70,70)
    c = 102, 204, 153
    BLACK = 0,0,0
    h_line_start = 285, 455
    h_lint_end = 354, 455
    v_line_start = 320, 420
    v_lint_end = 320, 489
    pygame.draw.rect(screen, c, rect, 0)
    pygame.draw.rect(screen, BLACK, rect, 1) # 画黑色边框
    pygame.draw.line(screen, BLACK, h_line_start, h_lint_end, 1)
    pygame.draw.line(screen, BLACK, v_line_start, v_lint_end, 1)


    # 画门
    rect = pygame.Rect(445,520,55,80)
    c = 255, 153, 51
    pygame.draw.rect(screen, c, rect, 0)

    # 画门把手
    pos = 490, 570
    r = 6
    c = 102, 102, 102
    pygame.draw.circle(screen, c, pos, r)

    # 红色屋檐 + 黄色三角形

    pos_list = [(200, 390), (600, 390), (560, 330), (240, 330)]
    c1 = 255, 51,51
    triangle_list = [(355, 390), (445, 390), (400, 330)]
    c2 = 255, 255, 0
    pygame.draw.polygon(screen, c1, pos_list, 0)
    pygame.draw.polygon(screen,c2, triangle_list, 0)

    # 画烟囱
    rect = pygame.Rect(280,290,25,40)
    c = 153, 0, 51
    pygame.draw.rect(screen, c, rect)

    # 画三个黑烟
    pos_list = [(295, 265), (320, 240), (340 ,220)]
    for index, pos  in enumerate(pos_list):
        pygame.draw.circle(screen, BLACK, pos, 12 - index * 2)

    pygame.display.update()
    while 1:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()
        
    pygame.quit()


def hand_movement():
    pygame.init()
    screen = pygame.display.set_mode((800, 600))
    WHITE = 255, 255, 255
    screen.fill(WHITE)

    GREEN = 0, 255, 0
    dx, dy = 0, 0
    size = width, height = 100, 100
    step = 1

    pygame.display.update()
    while 1:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()

        if dx <= 800 or dy <= 600:
            pygame.draw.rect(screen, GREEN, ((dx, dy), size))
            pygame.display.update()
            dx += step
            dy += step
            time.sleep(0.1)

    pygame.quit()

def hand_movement2():
    pygame.init()
    screen = pygame.display.set_mode((800, 600))
    WHITE = 255, 255, 255
    screen.fill(WHITE)

    GREEN = 0, 255, 0
    dx, dy = 0, 0
    size = width, height = 100, 100
    step = 1

    pygame.display.update()
    while 1:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()

        if dx <= 800 or dy <= 600:
            screen.fill(WHITE)
            pygame.draw.rect(screen, GREEN, ((dx, dy), size))
            pygame.display.update()
            dx += step
            dy += step
            time.sleep(0.1)

    pygame.quit()


def auto_move():
    pygame.init()
    screen = pygame.display.set_mode((800, 600))
    WHITE = 255, 255, 255
    screen.fill(WHITE)
    GREEN = 0, 255, 0
    rect = pygame.draw.rect(screen, GREEN, (0,0, 100, 100))
    dx = dy = 1
    while 1:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()
        screen.fill(WHITE)
        rect.move(dx, dy)
        pygame.draw.rect(screen,GREEN, rect)
        pygame.display.update()
        time.sleep(0.1)
    pygame.quit()

def auto_move2():
    pygame.init()
    screen = pygame.display.set_mode((800, 600))
    WHITE = 255, 255, 255
    screen.fill(WHITE)
    GREEN = 0, 255, 0
    rect = pygame.draw.rect(screen, GREEN, (0,0, 100, 100))
    dx = dy = 1
    while 1:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()
        screen.fill(WHITE)
        rect = pygame.draw.rect(screen,GREEN, rect.move(0, dy))
        pygame.display.update()
        time.sleep(0.1)
    pygame.quit()


def auto_move3():
    pygame.init()
    screen = pygame.display.set_mode((800, 600))
    WHITE = 255, 255, 255
    screen.fill(WHITE)
    GREEN = 0, 255, 0
    rect = pygame.draw.rect(screen, GREEN, (0,0, 100, 100))
    dx = dy = 1
    while 1:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()
        screen.fill(WHITE)
        rect.move_ip(dx, 0)
        pygame.draw.rect(screen,GREEN, rect)
        pygame.display.update()
        time.sleep(0.1)
    pygame.quit()
if __name__ == '__main__':
    auto_move2()

